package com.jrzn.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jrzn.base.BaseActivity;
import com.nsjr.jrznandroid.R;

/**
 * Created by haokai on 2016/5/18.
 */
public class BaseFragment extends Fragment {
    public TextView tv, tv_left, tv_right;
    public LinearLayout back, add;
    public ImageView app_title_iv_right;
    public ImageView iv_right, iv_left;
    protected BaseActivity activity;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }
    /**
     * 设置title标题 不同type不同布局
     *
     * @param title
     * @param left_drawable
     * @param right_drawable
     *            0为没有 1为默认图标 也可输入res地址自定义图标
     */
    public void initTitleIcon(View view, String title, int left_drawable,
                              int right_drawable, int right_drawable2) {
        tv = (TextView) view.findViewById(R.id.app_title);
        iv_right = (ImageView) view.findViewById(R.id.app_title_iv1_right);
        ImageView iv_right2 = (ImageView) view
                .findViewById(R.id.app_title_iv2_right);
        iv_left = (ImageView) view.findViewById(R.id.app_title_iv_left);
        back = (LinearLayout) view.findViewById(R.id.app_back_click);
        add = (LinearLayout) view.findViewById(R.id.app_add_click);
        tv_left = (TextView) view.findViewById(R.id.app_title_tv_left);
        tv_left.setVisibility(View.GONE);
        if ("".equals(title)) {
            tv.setVisibility(View.GONE);
        } else {
            tv.setText(title);
        }

        switch (left_drawable) {
            case 0:
                iv_left.setVisibility(View.GONE);
                break;
            case 1:
                iv_left.setVisibility(View.VISIBLE);
                back.setVisibility(View.VISIBLE);
                iv_right2.setVisibility(View.VISIBLE);
                break;

            default:
                iv_left.setVisibility(View.VISIBLE);
                iv_left.setImageResource(left_drawable);
                back.setVisibility(View.VISIBLE);
                iv_right2.setVisibility(view.VISIBLE);
                break;
        }
        switch (right_drawable) {
            case 0:
                iv_right.setVisibility(View.GONE);
                break;
            case 1:
                iv_right.setVisibility(View.VISIBLE);
                add.setVisibility(View.VISIBLE);
                break;

            default:
                add.setVisibility(View.VISIBLE);
                iv_right.setVisibility(View.VISIBLE);
                iv_right.setImageResource(right_drawable);
                break;
        }
        switch (right_drawable2) {
            case 0:
                iv_right2.setVisibility(View.GONE);
                break;
            case 1:
                iv_right2.setVisibility(View.VISIBLE);
                add.setVisibility(View.VISIBLE);
                break;

            default:
                add.setVisibility(View.VISIBLE);
                iv_right2.setVisibility(View.VISIBLE);
                iv_right2.setImageResource(right_drawable2);
                break;
        }

    }

    /**
     * 自定义修改title左右文字
     *
     * @param left_text
     * @param right_text
     */
    public void initTitleText(View view, String left_text, String right_text) {
        tv_left = (TextView) view.findViewById(R.id.app_title_tv_left);
        tv_right = (TextView) view.findViewById(R.id.app_title_tv_right);
        if (!TextUtils.isEmpty(left_text)) {
            tv_left.setText(left_text);
            tv_left.setVisibility(View.VISIBLE);
            back.setVisibility(View.VISIBLE);
        } else {
            tv_left.setVisibility(View.INVISIBLE);
        }
        if (!TextUtils.isEmpty(right_text)) {
            tv_right.setText(right_text);
            tv_right.setVisibility(View.VISIBLE);
            add.setVisibility(View.VISIBLE);
        } else {
            tv_right.setVisibility(View.GONE);
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activity = (BaseActivity) getActivity();
     }
}
